<?php

class Admin_IndexController extends Lib2k_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
    }
    
    
    public function ajaxparseAction()
    {
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(TRUE);     
        
        $startPos = (int) $this->getRequest()->get('startPos');
        $curPos = (int) $this->getRequest()->get('curPos');
        $endPos = (int) $this->getRequest()->get('endPos');
       // Zend_Debug::dump($curPos);
        $filmixParser = new Lib2k_Parsing_Filmix(); 
        $data = $filmixParser->parsePage($curPos);

        $filmixModel = new Model_Film();
        foreach($data as $item) {
            $filmixModel->saveFilm($item['title'], $item['link'], $item['rating'], $item['image'], $item['description'], $item['categories']);
                      
        };        
        
        
        
        $curPos++;
        echo json_encode(array('result' => true, 'startPos' => $startPos, 'curPos' => $curPos, 'endPos' => $endPos));   
    }


}

